#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
        int sum = 0;
        for (int i = 0; i < timeSeries.size(); i++)
        {
            if (i < timeSeries.size() - 1 && timeSeries[i + 1] - timeSeries[i] < duration)
                sum += timeSeries[i + 1] - timeSeries[i];
            else
                sum += duration;
        }
        return sum;
    }
};